package com.sl.au.config;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.sl.au.service.EventProcessToEvaluateUserService;
import com.sl.au.service.UserTrajectoryService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTask {
	@Autowired
	EventProcessToEvaluateUserService eventProcessToEvaluateUserService;
	@Autowired
	UserTrajectoryService userTrajectoryService;
	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private Integer count0 = 1;

	/*@Scheduled(cron = "0 1 0 * * ?")//每天0点过1分后执行任务*/
	/*@Scheduled(cron = "0 1 0 * * ?")//每天0点过1分后执行任务
	public void reportCurrentTime() throws InterruptedException {
		indexService.getAafterSale();
		System.out.println(String.format("---第%s次执行，当前时间为：%s", count0++, dateFormat.format(new Date())));
	}*/
	 @Scheduled(cron="0/60 * *  * * ? ")
	 public void calcOutTime(){
		 try{
			  this.eventProcessToEvaluateUserService.GetAcceptLimitProcessCountWithoutMark();
			  this.eventProcessToEvaluateUserService.GetDealLimitProcessCountWithoutMark();
			 System.out.println(String.format("---第%s次执行自动扣分判断，当前时间为：%s", count0++, dateFormat.format(new Date()))); 
		 }
		 catch(Exception ex){
			 
		 }
	 }

	 @Scheduled(cron = "0 1 0 * * ?")//每天0点过1分后执行任务
	 public void delTrajectory(){
		 try{
			 int count = userTrajectoryService.saveHistoryTrajectory();
			 userTrajectoryService.getRepository().deleteAll();
			 System.out.println("---执行生成用户历史轨迹 "+ count + " 条并清除用户轨迹信息，当前时间为：" + dateFormat.format(new Date())); 
		 }
		 catch(Exception ex){
			 
		 }
		 
	 }
	 
	 
	 @Scheduled(cron="0/30 * *  * * ? ")
	 public void checkUpOnline(){
		 try{
			 //AppWebSocketTask.doWork();
			 System.out.println( "---执行检查在线人员，当前在线人数："+ AppWebSocketTask.getOnlineCount() +"人，当前时间为：" + dateFormat.format(new Date())); 
		 }
		 catch(Exception ex){
			 
		 }
	 }
}
